/**
 * 物料管理数据model
 */
import {getPageManageList,saveObj,disableCourse,enableCourse,getList,getClassList,getClassStudentList,getTeacherList,getInfo,batchSaveSchedule,
    getScheduleList,saveCourseStage,deleteCourseStage,GetCourseSchedulingCourseCount,getMajorList,getCourseScheduleClassList,saveCourseScheduleClass,
    saveTeacherNotScheduleRule,saveClassNotScheduleRule,saveSchedule,getNotFullCourseList,updateScheduleTime,
    getCourseTextBookList,saveCourseTextBook,deleteCourseTextBook} from 'api/courseManageApi';

const courseManage = {
    state: {
        courseManagePageData:[],
        courseSelectList:[],
        classSelectList:[],
        majorSelectList:[],
        teacherSelectList:[],
        studentSelectList:[],
        page: {
            currentPage: 1,
            pageSize: 5,
            total: 0
        },
        queryPara:{
            name: '',
        }
    },
    mutations: {
        loadCourseManageMut(state, obj){
            if (obj.rows !== '') {
                state.courseManagePageData = obj.rows;
                state.page.currentPage = obj.currentPage;
                state.page.pageSize = obj.pageSize;
                state.page.total = obj.total;
            }
        },
        loadCourseSelectMut(state, obj){
            let courseSelectList = [];
            if (obj.code === 0) {
                if (obj.data && obj.data.length > 0){
                    obj.data.forEach((item, index) => {
                        courseSelectList.push({
                            index : index,
                            value : item.id,
                            label : item.name  ,
                            record:{...item}
                        })
                    })
                }
                state.courseSelectList = courseSelectList;
            }
        },
        loadClassSelectMut(state, obj){
            let classSelectList = [];
            if (obj.code === 0) {
                if (obj.data && obj.data.length > 0){
                    obj.data.forEach((item, index) => {
                        classSelectList.push({
                            index : index,
                            value : item.id,
                            label : item.parentName + '-'+ item.name  ,
                            record:{...item}
                        })
                    })
                }
                state.classSelectList = classSelectList;
            }
        },
        loadTeacherSelectMut(state, obj){
            let teacherSelectList = [];
            if (obj.code === 0) {
                if (obj.data && obj.data.length > 0){
                    obj.data.forEach((item, index) => {
                        teacherSelectList.push({
                            index : index,
                            value : item.id,
                            label : item.orgName + '-'+item.name  ,
                            record:{...item}
                        })
                    })
                }
                state.teacherSelectList = teacherSelectList;
            }
        },
        loadStudentSelectMut(state, obj){
            let studentSelectList = [];
            if (obj.code === 0) {
                if (obj.data && obj.data.length > 0){
                    obj.data.forEach((item, index) => {
                        studentSelectList.push({
                            index : index,
                            value : item.id,
                            label : item.name  ,
                            record:{...item}
                        })
                    })
                }
                state.studentSelectList = studentSelectList;
            }
        },loadMajorSelectListMut(state, obj){
            let majorSelectList = [];
            if (obj.code === 0) {
                if (obj.data && obj.data.length > 0){
                    obj.data.forEach((item, index) => {
                        majorSelectList.push({
                            index : index,
                            value : item.id,
                            label : item.name  ,
                            record:{...item}
                        })
                    })
                }
                state.majorSelectList = majorSelectList;
            }
        },
        setCourseManageQueryPrams(state, obj){
            state.queryPara = obj;
        }

    },
    actions: {
        /*获取分页列表*/
        getCourseManagePageListAct (context, para) {
            return getPageManageList(para).then(res => {
                context.commit("loadCourseManageMut",res.data);
            });
        },
        /*获取列表*/
        getCourseSelectListAct (context, para) {
            return getList(para).then(res => {
                context.commit("loadCourseSelectMut",res.data);
            });
        },
        /*获取列表*/
        getTeacherSelectListAct (context, para) {
            return getTeacherList(para).then(res => {
                context.commit("loadTeacherSelectMut",res.data);
            });
        },
        /*获取列表*/
        getClassSelectListAct (context, para) {
            return getClassList(para).then(res => {
                context.commit("loadClassSelectMut",res.data);
            });
        },
        /*获取学生列表*/
        getStudentSelectListAct (context, para) {
            return getClassStudentList(para).then(res => {
                context.commit("loadStudentSelectMut",res.data);
            });
        },
        /*获取专业列表*/
        getMajorSelectListAct (context, para) {
            return getMajorList(para).then(res => {
                context.commit("loadMajorSelectListMut",res.data);
            });
        },
        /*新增/编辑*/
        saveCourseAct (context, para) {
            return saveObj(para).then(res=>{
                return res.data;
            });
        },
        /*详情*/
        getCourseInfoAct (context, para) {
            return getInfo(para).then(res=>{
                return res.data;
            });
        },
        /*启用*/
        enableCourseAct (context, para) {
            return enableCourse(para).then(res=>{
                return res.data;
            });
        },
        /*启用*/
        disableCourseAct (context, para) {
            return disableCourse(para).then(res=>{
                return res.data;
            });
        },
        /*启用*/
        batchSaveScheduleAct (context, para) {
            return batchSaveSchedule(para).then(res=>{
                return res.data;
            });
        },updateScheduleTimeAct (context, para) {
            return updateScheduleTime(para).then(res=>{
                return res.data;
            });
        },
        saveScheduleAct (context, para) {
            return saveSchedule(para).then(res=>{
                return res.data;
            });
        },
        /*启用*/
        getScheduleListAct (context, para) {
            return getScheduleList(para).then(res=>{
                return res.data;
            });
        },
        getNotFullCourseListAct (context, para) {
            return getNotFullCourseList(para).then(res=>{
                return res.data;
            });
        },

        /*新增/编辑*/
        saveCourseStageAct (context, para) {
            return saveCourseStage(para).then(res=>{
                return res.data;
            });
        },
        /*删除*/
        deleteCourseStageAct (context, para) {
            return deleteCourseStage(para).then(res=>{
                return res.data;
            });
        },/*查询课程数量*/
        GetCourseSchedulingCourseCountAct (context, para) {
            return GetCourseSchedulingCourseCount(para).then(res=>{
                return res.data;
            });
        },
        /*获取课程上课班级*/
        getCourseScheduleClassListAct (context, para) {
            return getCourseScheduleClassList(para).then(res=>{
                return res.data;
            });
        },
        /*保存课程上课班级*/
        saveCourseScheduleClassAct (context, para) {
            return saveCourseScheduleClass(para).then(res=>{
                return res.data;
            });
        },
        /*保存教师不排课规则*/
        saveTeacherNotScheduleRuleAct (context, para) {
            return saveTeacherNotScheduleRule(para).then(res=>{
                return res.data;
            });
        },
        /*保存班级不排课规则*/
        saveClassNotScheduleRuleAct (context, para) {
            return saveClassNotScheduleRule(para).then(res=>{
                return res.data;
            });
        },
        getCourseTextBookListAct (context, para) {
            return getCourseTextBookList(para).then(res=>{
                return res.data;
            });
        },
        saveCourseTextBookAct (context, para) {
            return saveCourseTextBook(para).then(res=>{
                return res.data;
            });
        },
        deleteCourseTextBookAct (context, para) {
            return deleteCourseTextBook(para).then(res=>{
                return res.data;
            });
        },

    }
};

export default courseManage;
